package listbyorder.access001_100.test78;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;

/**
 * 有点小套路
 * @author code_yc
 * @version 1.0
 * @date 2020/6/4 10:41
 */
public class Solution1 {

    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> res = new ArrayList<>();
        if (nums == null || nums.length == 0) return res;
        dfs(res, nums, 0, nums.length, new ArrayDeque<Integer>());
        return res;
    }

    private void dfs(List<List<Integer>> res, int[] nums, int s, int e, ArrayDeque<Integer> path) {
        res.add(new ArrayList<>(path));   // 不管到那个位置，都将当前的path加入数组
        for (int i = s; i < e; i++) {
            path.addLast(nums[i]);
            dfs(res, nums, i + 1, e, path);  // 当前位置元素要
            path.removeLast();
        }
    }

}
